<template>
  <div class="app-container">
<!--    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">-->
<!--      <el-form-item label="标题" prop="title">-->
<!--        <el-input-->
<!--            v-model="queryParams.title"-->
<!--            placeholder="请输入标题"-->
<!--            clearable-->
<!--            @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->


<!--      <el-form-item>-->
<!--        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>-->
<!--        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
<!--        -->

<!--      </el-form-item>-->
<!--    </el-form>-->



    <div class="cont" >
      <div  class="cont-invitation" v-for="item in promInvitationList">
        <!--用户名和时间-->
        <div style="display: flex;height: 60px; flex-direction: row; margin: 10px 10px 5px 10px ">
          <img :src="item.avatar" :width="35" :height="35" style="border-radius: 50%;margin: 10px 0 0 20px">
          <!--          用户名-->
          <h3 style="margin-left: 12px;color: #2c3e50">
            {{item.nickName}}
          </h3>
          <div style="margin: 27px 0 0 10px;color: #97a8be;font-size: 10px">

            {{item.creatTime}}
          </div>
        </div>
        <!--      内容-->
        <div style="margin: 0px 20px 5px 20px">
          <div style="font-size: 25px;font-weight: 600">
            {{item.title}}
          </div>
          <div style="font-size: 18px; margin: 0" v-html="item.content">
          </div>
        </div>
        <div style="display: flex;">
          <div v-for="(img) in item.imgUrlList" style="margin: 0px 10px 10px 15px">
            <img :src="img" :width="100" :height="100">

          </div>
        </div>

        <div style="margin: 20px">
          <el-button type="success" @click="checkInvi(item.id,1)" plain style="margin-right: 20px">通过</el-button>
          <el-button type="danger" @click="checkInvi(item.id,2)"  plain>不通过</el-button>
        </div>


      </div>
    </div>



  </div>
</template>

<script>
import { listPromInvitation, getPromInvitation, delPromInvitation, addPromInvitation, updatePromInvitation , getBaseUrl, deleteAdopImg} from "@/api/petSys/promInvitation";
import {listTypeList} from "@/api/petSys/otherComm";
import {getToken} from "@/utils/auth";

export default {
  name: "InviCheck",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 发布帖子表格数据
      promInvitationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        title: null,
        content: null,
        promUserId: null,
        creatTime: null,
        imgUrl: null,
        upvoteNum: null,
        browseNum: null,
        petType: null,
        checkType: 0,
        checkTime: null,
        checkUserId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      petTypeList:[],
      headers: { Authorization: "Bearer " + getToken() },
      dialogImageUrl: '',
      dialogVisible: false,
      fileUrlList: [],
      bastUrl:""
    };
  },
  created() {
    getBaseUrl().then(response => {
      this.bastUrl = response;
    });
    this.getList();
    this.getPetTypeList();
  },
  methods: {
    /** 查询发布帖子列表 */
    getList() {
      this.loading = true;
      listPromInvitation(this.queryParams).then(response => {
        this.promInvitationList = response.rows;
        console.log(this.promInvitationList)
        this.promInvitationList.forEach(item=>{
          console.log("这里是item",item)

          for (var i = 0; i < item.imgUrlList.length; i++) {
            item.imgUrlList[i] = item.imgUrlList[i].replace(/\\/g, "/")
            item.imgUrlList[i] = "/" + item.imgUrlList[i]
            console.log(item.imgUrlList[i])

          }


        })
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        title: null,
        content: null,
        promUserId: null,
        creatTime: null,
        updateTime: null,
        imgUrl: null,
        upvoteNum: null,
        browseNum: null,
        petType: null,
        checkType: null,
        checkTime: null,
        checkUserId: null

      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加发布帖子";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPromInvitation(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改发布帖子";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        this.form.imgUrl=""
        this.fileUrlList.forEach(item => {
          this.form.imgUrl += item + ";"
        })
        this.$refs.upload.clearFiles();
        if (valid) {
          if (this.form.id != null) {
            updatePromInvitation(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            console.log(this.form)
            addPromInvitation(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除发布帖子编号为"' + ids + '"的数据项？').then(function() {
        return delPromInvitation(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    getPetTypeList(){
      listTypeList().then(response => {
        this.petTypeList = response.rows;
      });
    },
    uploadSuccess(response, file, fileList) {

      console.log(response)

      this.fileUrlList.push(response.data);


    },
    limitEvent(){
      this.$modal.alertWarning("最大只能选择三张图片")
    },
    handleRemove(file, fileList){
      this.fileUrlList.splice(this.fileUrlList.indexOf(file.response.data), 1);
      deleteAdopImg(file.response.data).then(response => {
        console.log(response)
      })

    },

    handlePictureCardPreview(file) {
      console.log(file)
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    handleProgress(event, file, fileList){


      if (file.raw.type.indexOf("image/") == -1) {
        this.$refs.upload.abort(file);
        fileList.splice(fileList.indexOf(file),1);
        this.$modal.msgError("文件格式错误，请上传图片类型,如：JPG，PNG后缀的文件。");
      }

    },
    checkInvi(inviId,checkFlag){
      this.form.id = inviId;
      this.form.checkType = checkFlag;
      updatePromInvitation(this.form).then(response => {
        this.getList();
        this.$modal.msgSuccess("审核成功");
      })
    }


  }
};
</script>
<style>
body, html {
  margin: 0;
  padding: 0;
  height: 100%;
}

.app-container {
  height: 100%;
}
.cont {
  height: 95%;
  overflow: auto;
  //background: #F4F5F7;
}
section {
  height: 80%;
}
.cont-invitation{
  margin: 10px;
  background: #F9F9F9;
  border-bottom: 1px solid #E4E7EC;
  border-top: 1px solid #E4E7EC;
}
</style>
